import { TYPES } from '../reducers/reportReducer';
import Http from '../../../utils/http';
import _ from 'lodash';
import {
  Toast,
} from 'antd-mobile-rn';
import { i18n } from '../../../i18n/index';

export const getSummaryReport = (date, employee = 'All Employees') => async dispatch => {
  try {
    const http = new Http();

    dispatch({ type: TYPES.GET_SUMMARY_REPORT });

    const { status, data } = await http.post('getsummaryreport', { date });

    if (status) {
      const { result } = data;
      dispatch({ type: TYPES.GET_SUMMARY_REPORT_SUCCESS, summary: result.report });
    } else {
      throw new Exception();
    }
  } catch (_) {
    dispatch({ type: TYPES.GET_SUMMARY_REPORT_FAIL });

    Toast.offline(i18n.t('report.error.getsummaryreport'), 2);
  }
};